﻿using System;
using System.Collections;
using System.Collections.Generic;
//using IBatisNet.DataAccess;
using Wsitech.Model;
using Wsitech.Utility;

namespace Wsitech.BLL
{
    /// <summary>
    /// 功能：     PositionInfo业务逻辑实现
    /// 作者：     LI
    /// 日期：     5/27/2012
    /// </summary>
    public class PositionInfoBLL
    {
        private Wsitech.Persistence.Interface.IPositionInfoDao dao = null;

        private PositionInfoBLL()
        {
            dao = Wsitech.Persistence.Dao.PositionInfoSqlMapDao.Instance;
        }

        #region （懒汉）单例模式
        private static PositionInfoBLL instance = null;
        private static object syncRoot = new object();
        public static PositionInfoBLL Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new PositionInfoBLL();
                        }
                    }
                }
                return instance;
            }
        }
        #endregion


        #region	基本功能 不能修改


        /// <summary>
        /// 根据主键得到明细
        /// </summary>
        /// <returns></returns>
        public PositionInfo GetDetail(System.String positionid)
        {
            try
            {
                return dao.GetDetail(positionid);
            }
            catch
            {
                throw;
            }
        }


        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public IList<PositionInfo> GetList()
        {
            try
            {
                IList<PositionInfo> list = dao.GetList();
                return list;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="TopCounts"></param>
        /// <returns></returns>
        private IList<PositionInfo> GetListByParams(object TopCounts, PositionInfo positioninfo)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("TopCounts", TopCounts);
                IList<PositionInfo> list = dao.GetListByParams(ht);
                return list;
            }
            catch
            {
                throw;
            }
        }



        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="positioninfo"></param>
        /// <returns></returns>
        public object Add(PositionInfo positioninfo)
        {
            try
            {
                LogInfoBLL.Instance.AddLog(UtilityEnum.Operation.Add, GetDetail(positioninfo.PositionId));
                return dao.Add(positioninfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="positioninfo"></param>
        /// <returns></returns>
        public int Update(PositionInfo positioninfo)
        {
            try
            {
                LogInfoBLL.Instance.AddLog(UtilityEnum.Operation.Update, GetDetail(positioninfo.PositionId));
                return dao.Update(positioninfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="PositionId"></param>
        /// <returns></returns>
        public int Delete(System.String positionid)
        {
            try
            {
                return dao.Delete(positionid);
            }
            catch
            {
                throw;
            }
        }

        #endregion


        #region 扩展功能

        #endregion

        public void ChangeState(string jobid, Utility.UtilityEnum.State state)
        {
            PositionInfo job = dao.GetDetail(jobid);
            if (job != null)
            {
                job.State = (int)state;

                job.UpdateTime = DateTime.Now;
                Update(job);
            }
        }

        public void AddPosition(string companyid, string positionname, string department, string workplace, string requirements, string responsibility, string contracts)
        {
            PositionInfo job = new PositionInfo();
            job.PositionId = Guid.NewGuid().ToString();
            job.CompanyId = companyid;
            job.PositionName = positionname;
            job.Department = department;
            job.WorkPlace = workplace;
            job.Requirements = requirements;
            job.Responsibility = responsibility;
            job.Contracts = contracts;

            job.CreateTime = DateTime.Now;
            job.UpdateTime = DateTime.Now;

            job.State = (int)UtilityEnum.State.Disable;

            Add(job);
        }


        /// <summary>
        /// 查询联想控股本部招聘信息
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public IList<PositionInfo> GetActiveListByCompanyId(string companyid)
        {
            Hashtable ht = new Hashtable();
            ht.Add("state", (int)UtilityEnum.State.Enable);
            ht.Add("companyId", companyid);

            return dao.GetListByParams(ht);
        }

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public IList<PositionInfo> GetPagedList(int pageindex, int pagesize, ref int count)
        {
            return dao.GetPagedList(null, pageindex, pagesize, ref count);
        }
    }
}
